﻿Public Class SearchResourcesForm
    Public idSelected As Integer

    Private Sub SearchResourcesForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        GenericAdministrator.loadGrid(Me.dgvSearchResources, Me.bdnSearchResources, ResourceAdministrator.search)
        Me.setDataGridViewHeaders()
    End Sub

    Private Sub cmdSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSearch.Click
        Dim id As Integer = Nothing
        If Me.txtId.Text <> "0" Then
            If Me.txtId.Text <> "" Then
                id = CType(Me.txtId.Text, Integer)
            End If
            Dim resource As New Resource(id, Me.txtFirstname.Text, Me.txtSurname.Text, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing)
            GenericAdministrator.loadGrid(Me.dgvSearchResources, Me.bdnSearchResources, ResourceAdministrator.searchDataByFilter(resource))
        Else
            MsgBox("Ha ingresado un legajo invalido.", vbCritical, "Importante")
        End If
    End Sub

    Private Sub bdnDeleteItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bdnDeleteItem.Click
        Dim id As Integer = Me.dgvSearchResources.CurrentRow.Cells(0).Value
        Dim resource As New Resource(id)
        Dim confirmacion As Integer
        confirmacion = MsgBox("¿Está seguro que desea Eliminar el Recurso seleccionado?", vbYesNo + vbQuestion + vbDefaultButton2, "Salir")
        If confirmacion = vbYes Then
            ResourceAdministrator.disabled(resource)
            GenericAdministrator.loadGrid(Me.dgvSearchResources, Me.bdnSearchResources, ResourceAdministrator.search)
        End If
    End Sub

    Private Sub bdnEditButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bdnEditButton.Click
        idSelected = Me.dgvSearchResources.CurrentRow.Cells(0).Value
        Me.Close()
        Dim resourceForm As New ResourceForm(Me)
        resourceForm.Show()
    End Sub

    Private Sub setDataGridViewHeaders()
        Me.dgvSearchResources.Columns(0).HeaderText = "Legajo"
        Me.dgvSearchResources.Columns(1).HeaderText = "Nombres"
        Me.dgvSearchResources.Columns(2).HeaderText = "Apellido"
        Me.dgvSearchResources.Columns(3).HeaderText = "Email"
        Me.dgvSearchResources.Columns(4).HeaderText = "Fecha Alta"
        Me.dgvSearchResources.Columns(5).HeaderText = "Costo x Hora"
    End Sub

    Private Sub txtId_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtId.KeyPress
        ViewValidators.isInteger(e)
    End Sub
End Class